package com.laiketui.user.services.dubbo;

import com.alibaba.csp.sentinel.util.StringUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.laiketui.common.api.PublicCouponService;
import com.laiketui.common.api.PublicGoodsService;
import com.laiketui.common.api.PublicUserService;
import com.laiketui.common.api.PubliceService;
import com.laiketui.common.api.ocr.VerifyService;
import com.laiketui.common.api.openUser.OpenUserService;
import com.laiketui.common.mapper.*;
import com.laiketui.common.utils.tool.BankTool;
import com.laiketui.common.utils.tool.ImgUploadUtils;
import com.laiketui.common.utils.tool.MobileUtils;
import com.laiketui.common.utils.tool.cache.RedisDataTool;
import com.laiketui.common.utils.tool.data.DataCheckTool;
import com.laiketui.common.utils.tool.jwt.JwtUtils;
import com.laiketui.common.utils.tool.str.StringUtils;
import com.laiketui.core.cache.RedisUtil;
import com.laiketui.core.common.SplitUtils;
import com.laiketui.core.exception.LaiKeAPIException;
import com.laiketui.core.exception.LaiKeCommonException;
import com.laiketui.core.lktconst.GloabConst;
import com.laiketui.core.utils.tool.DataUtils;
import com.laiketui.core.utils.tool.DateUtil;
import com.laiketui.core.utils.tool.WxOpenIdUtils;
import com.laiketui.domain.config.ConfigModel;
import com.laiketui.domain.config.ProductConfigModel;
import com.laiketui.domain.distribution.UserDistributionModel;
import com.laiketui.domain.home.SystemMessageModel;
import com.laiketui.domain.lktconst.DictionaryConst;
import com.laiketui.domain.lktconst.ErrorCode;
import com.laiketui.domain.log.RecordDetailsModel;
import com.laiketui.domain.log.RecordModel;
import com.laiketui.domain.mch.BankCardModel;
import com.laiketui.domain.mch.MchModel;
import com.laiketui.domain.mch.UserCollectionModel;
import com.laiketui.domain.message.MessageLoggingModal;
import com.laiketui.domain.ocr.VerifyBusinessData;
import com.laiketui.domain.presell.PreSellGoodsModel;
import com.laiketui.domain.presell.PreSellRecordModel;
import com.laiketui.domain.systems.SystemTellModel;
import com.laiketui.domain.user.FinanceConfigModel;
import com.laiketui.domain.user.User;
import com.laiketui.domain.user.UserBusinessInfo;
import com.laiketui.domain.user.WithdrawModel;
import com.laiketui.domain.vo.MainVo;
import com.laiketui.domain.vo.UserLoginVo;
import com.laiketui.domain.vo.Withdrawals1Vo;
import com.laiketui.domain.vo.user.*;
import com.laiketui.root.annotation.DubboApiMethod;
import com.laiketui.root.license.CryptoUtil;
import com.laiketui.root.license.Md5Util;
import com.laiketui.user.api.UserBaseService;
import com.laiketui.user.common.consts.UserConst;
import com.laiketui.user.vo.UserSignVo;
import jdk.nashorn.internal.runtime.GlobalConstants;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.time.FastDateFormat;
import org.apache.dubbo.config.annotation.DubboService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import javax.xml.bind.annotation.XmlElementDecl;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.URLDecoder;
import java.util.*;


/**
 * 用户接口实现
 *
 * @author Trick
 * @date 2020/9/23 9:22
 */
@DubboService(version = "1.0.0")
public class UserBaseDubboServiceImpl implements UserBaseService {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private PublicUserService publicUserService;

    @Autowired
    private SystemTellModelMapper systemTellModelMapper;

    @Autowired
    ProductConfigModelMapper productConfigModelMapper;

    @Autowired
    ProductListModelMapper productListModelMapper;

    @Autowired
    PubliceService publicService;

    @Autowired
    ConfiGureModelMapper confiGureModelMapper;

    @Autowired
    private PublicGoodsService publicGoodsService;

    @Autowired
    private UserBusinessInfoMapper userBusinessInfoMapper;

    @Autowired
    private VerifyService verifyService;

    @Autowired
    private OpenUserService openUserService;

    @Override
    public User getUser(User user) throws LaiKeAPIException {
        return userBaseMapper.selectOne(user);
    }

    @Override
    @DubboApiMethod(apiKey = "com.laike.user.registerUser",
            login = false, module = UserConst.MODULE_NAME, version = "1.0.0")
    @Transactional(rollbackFor = Exception.class)
    public Map<String, Object> insertUser(UserRegisterVo vo) throws LaiKeAPIException {
        Map<String, Object> resultMap = new HashMap<>(16);
        try {
            boolean isExist;
            if (StringUtils.isEmpty(vo.getPhone())) {
                throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_SJHBNWK, "手机号不能为空");
            }
            if (StringUtils.isEmpty(vo.getMima())) {
                throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_MMBNWK, "密码不能为空");
            }
//            if (StringUtils.isEmpty(vo.getZhanghao())) {
//                throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_ZHBNWK, "账号不能为空");
//            }
            Integer userType = vo.getUserType();
            User user = new User();
            user.setMobile(vo.getPhone());
            user.setMima(vo.getMima());
            user.setZhanghao(vo.getPhone());
            //用户类型 1.C端用户 2.B端用户
            user.setUser_type(userType);
            if(userType == 2){
                user.setRole_id(GloabConst.RoleType.ROLE_MEMBER);
            }
            //校验数据格式
            user = DataCheckTool.checkUserDataFormate(user);
            //验证短信
            Object messageCode = redisUtil.get(GloabConst.RedisHeaderKey.REGISTER_HEADER + user.getMobile());
            isExist = messageCode == null;
            if (isExist || !messageCode.toString().equals(vo.getKeyCode())) {
                throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_YZMBZQ, "验证码不正确");
            }

            //检查账户/手机号是否已存在
            User userTemp = new User();
            userTemp.setZhanghao(user.getZhanghao());
            isExist = this.isRegister(vo.getStoreId(), user.getZhanghao());
            if (!isExist && !this.isRegister(vo.getStoreId(), user.getMobile())) {
                //注册
                publicUserService.register(vo, vo.getPid(), user);
                //自动登录
//                publicUserService.loginSuccess(user, user.getAccess_id(), vo.getPid());
            } else {
                logger.debug("{}或者{} 该账号已被注册!", user.getZhanghao(), user.getMobile());
                throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_GZHYBZC, "该账号已被注册", "insertUser");
            }
        } catch (LaiKeAPIException l) {
            throw l;
        } catch (Exception e) {
            logger.error("用户注册 异常", e);
            throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_WLYC, "网络异常", "insertUser");
        }
        return resultMap;
    }

    @Override
    @DubboApiMethod(apiKey = "com.laike.user.isRegister",
            login = false, module = UserConst.MODULE_NAME, version = "1.0.0")
    public boolean isRegister(int storeId, String zhanghao) throws LaiKeAPIException {
        try {
            int flag = userBaseMapper.validataUserPhoneOrNoIsRegister(storeId, zhanghao);
            return flag > 0;
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("验证账号是否注册 异常" + e.getMessage());
            throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_WLYC, "网络异常", "isRegister");
        }
    }


    @DubboApiMethod(apiKey = "com.laike.user.sendSms",
            login = false, module = UserConst.MODULE_NAME, version = "1.0.0")
    @Override
    public boolean sendSms(String mobile,int smsType,int storeId) throws LaiKeAPIException {
        return publiceService.sendSms(storeId, mobile, GloabConst.VcodeCategory.TYPE_VERIFICATION, smsType, null);
    }

    @DubboApiMethod(apiKey = "com.laike.user.login",
            login = false, module = UserConst.MODULE_NAME, version = "1.0.0")
    @Transactional(rollbackFor = Exception.class)
    @Override
    public Map<String, Object> login(UserLoginVo user) throws LaiKeAPIException {
        Map<String, Object> resultMap = new HashMap<>(16);
        User userTemp = new User();
        Integer sellOrderNum = 0;
        try {
            //公告id
            Integer tell_id = 0;
            //公告标题
            String systemMsgTitle = "";
            //系统公告
            String systemMsg = "";
            //公告类型 1=系统维护 2=升级公告 3-- 普通公告
            int systemMsgType = 0;
            //维护开始、结束时间
            String systemMsgStartDate = "";
            String systemMsgEndDate = "";
            String token = user.getAccessId();
            String fatherUid = user.getPid();
            String lang = GloabConst.Lang.PHP_ZH_CN;
            if (GloabConst.Lang.JAVA_EN.equals(user.getLanguage())) {
                lang = GloabConst.Lang.PHP_EN_GB;
            }
            int wxStatus = 0;
            if (!StringUtils.isEmpty(user.getPhone()) && !StringUtils.isEmpty(user.getPassword())) {
                //账号或手机号
                if(!Objects.equals(GloabConst.StoreId.LUOCKOO_SHOP,user.getStoreId())){
                    user.setStoreId(GloabConst.StoreId.LUOCKOO_SHOP);
                }
                userTemp.setStore_id(user.getStoreId());
                userTemp.setZhanghao(user.getPhone());
                if(Objects.nonNull(user.getUserType())){
                    userTemp.setUser_type(user.getUserType());
                }
                //获取商城信息
                ConfigModel configModel = new ConfigModel();
                configModel.setStore_id(user.getStoreId());
                configModel = configModelMapper.selectOne(configModel);
                if(Objects.isNull(configModel)){
                    logger.error("获取不到商城信息 storeId:{}",user.getStoreId(),"配置信息");
                    throw new LaiKeAPIException("获取不到商城信息");
                }
                String openid = "";
                //获取openid
                if(StringUtils.isNotEmpty(user.getCode())){
                    openid = WxOpenIdUtils.getMiniOpenid(configModel.getAppid(), configModel.getAppsecret(), user.getCode());
                }
                //获取用户信息
                User userinfo = userBaseMapper.getUserByzhanghaoApp(userTemp);
                if (userinfo != null) {
                    logger.debug("该账号名称为{}", userinfo.getUser_name());
                    if (!StringUtils.isEmpty(userinfo.getMima())) {
                        String decoderPwd = CryptoUtil.strDecode(userinfo.getMima());
                        if (decoderPwd != null && decoderPwd.equals(user.getPassword())) {
                            //是否为小程序
                            if (DictionaryConst.StoreSource.LKT_LY_001.equals(user.getStoreType() + "")) {
                                if (StringUtils.isEmpty(userinfo.getWx_id())) {
                                    wxStatus = 1;
                                }
                            }
                            if(StringUtils.isNotEmpty(openid)){
                                userinfo.setOpenid(openid);
                            }
                            //登录成功流程
                            userinfo.setLang(lang);
                            publicUserService.loginSuccess(userinfo, token, fatherUid);
                            //新增修改微信openid
                            openUserService.updateOpenUser(userinfo,openid,user.getStoreId());
                            //预售待支付订单提醒
                            String startOfDay = DateUtil.getStartOfDay(new Date());
                            List<Integer> integers = preSellRecordModelMapper.countPending(userinfo.getStore_id(), userinfo.getUser_id());
                            if (integers != null && integers.size() > 0) {
                                for (int i = 0; i < integers.size(); i++) {
                                    Integer integer = integers.get(i);
                                    PreSellRecordModel preSellRecordModel = preSellRecordModelMapper.selectByPrimaryKey(integer);
                                    PreSellGoodsModel preSellGoodsModel = new PreSellGoodsModel();
                                    preSellGoodsModel.setProduct_id(preSellRecordModel.getProduct_id());
                                    preSellGoodsModel = preSellGoodsMapper.selectOne(preSellGoodsModel);
                                    //定金模式商品只有到了待付尾款时间才算订单提醒
                                    if (!Objects.isNull(preSellGoodsModel) && preSellGoodsModel.getSell_type().equals(PreSellGoodsModel.DEPOSIT_PATTERN)) {
                                        if (!DateUtil.dateFormate(preSellGoodsModel.getBalance_pay_time(), GloabConst.TimePattern.YMDHMS).equals(startOfDay)) {
                                            integers.remove(i);
                                            i--;
                                        }
                                    }
                                }
                                sellOrderNum = integers.size();
                            }
                            Map<String, Object> parmaMap = new HashMap<>(16);
                            parmaMap.put("store_id", 0);
                            parmaMap.put("startDate_lt", new Date());
                            parmaMap.put("endDate_gt", new Date());
                            parmaMap.put("type_sort", DataUtils.Sort.ASC.toString());
                            parmaMap.put("user_tell", SystemTellModel.TELL.YES);
                            parmaMap.put("user_store_id", user.getStoreId());
                            parmaMap.put("store_type", user.getStoreType());
                            parmaMap.put("read_id", userinfo.getUser_id());
                            List<Map<String, Object>> systemList = systemTellModelMapper.selectDynamic(parmaMap);
                            if (systemList.size() > 0) {
                                Map<String, Object> systemMap = systemList.get(0);
                                systemMsgTitle = MapUtils.getString(systemMap, "title");
                                systemMsg = MapUtils.getString(systemMap, "content");
                                systemMsgType = MapUtils.getIntValue(systemMap, "type");
                                tell_id = MapUtils.getInteger(systemMap, "id");
                                systemMsgEndDate = DateUtil.dateFormate(MapUtils.getString(systemMap, "enddate"), GloabConst.TimePattern.YMDHMS);
                                systemMsgStartDate = DateUtil.dateFormate(MapUtils.getString(systemMap, "startdate"), GloabConst.TimePattern.YMDHMS);
                            }
                            String info = "登录成功";
                            if (systemMsgType == 1){
                                info = "系统维护中";
                            }
                            //登陆成功
                            resultMap.put("token", token);
                            //系统公告
                            resultMap.put("systemMsgTitle", systemMsgTitle);
                            resultMap.put("systemMsg", systemMsg);
                            resultMap.put("systemMsgType", systemMsgType);
                            resultMap.put("tell_id", tell_id);
                            resultMap.put("systemMsgEndDate", systemMsgEndDate);
                            resultMap.put("systemMsgStartDate", systemMsgStartDate);
                            resultMap.put("info", info);
                            //登陆成功
                            resultMap.put("access_id", userinfo.getAccess_id());
                            String userName = userinfo.getUser_name();
                            resultMap.put("user_name", userName);
                            resultMap.put("user_id", userinfo.getUser_id());
                            resultMap.put("headimgurl", userinfo.getHeadimgurl());
                            resultMap.put("phone",userinfo.getMobile());
                            resultMap.put("userType",userinfo.getUser_type());
                            resultMap.put("signatoryName",userinfo.getSignatory_name());
                            resultMap.put("examineFlag",userinfo.getExamine_flag());
                            resultMap.put("submitFlag",userinfo.getSubmit_flag());
                            resultMap.put("y_password", 1);
                            resultMap.put("wx_status", wxStatus);
                            resultMap.put("sellOrderNum", sellOrderNum);
                            resultMap.put("lang", userinfo.getLang());
                            resultMap.put("roleId",userinfo.getRole_id());
                            return resultMap;
                        } else {
                            throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_ZHHMMBPP, "账户或密码不匹配", "login");
                        }
                    } else {
                        throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_NHWSZMM, "您还未设置密码", "login");
                    }
                } else {
                    throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_DLSBYHBCZ, "登录失败,用户不存在", "login");
                }
            }
        } catch (LaiKeAPIException l) {
            throw l;
        } catch (Exception e) {
            logger.error("登录 异常", e);
            throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_WLYC, "网络异常", "quit");
        }
        throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_DLSBCSCW, "登录失败,参数错误", "login");
    }

    @Override
    public UserSignVo getUserInfo(String token) throws LaiKeAPIException {
        UserSignVo userInfo = new UserSignVo();
        if(StringUtils.isEmpty(token)){
            throw new LaiKeAPIException("token参数为空 ");
        }
        User user = RedisDataTool.getRedisUserCache(token, redisUtil);
        if(user == null){
            throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_QZXDL, "请重新登录");
        }
        userInfo.setUserId(user.getUser_id());
        userInfo.setMobile(user.getMobile());
        return userInfo;
    }

    @Override
    public boolean loginSupply(UserLoginVo userLoginVo) throws LaiKeAPIException{
        boolean loginFlag = false;
        try{
            User user = RedisDataTool.getRedisUserCache(userLoginVo.getAccessId(), redisUtil);
            String password = "";
            if(user == null){
                throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_QZXDL, "请重新登录");
            }
            password = userLoginVo.getPassword();
            String decodePassword = CryptoUtil.strDecode(user.getMima());

            if(null != decodePassword && password.equals(decodePassword)){
                loginFlag = true;
            }else{
                throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_ZHHMMBPP, "密码不正确");
            }
            return loginFlag;
        }catch (LaiKeAPIException l){
            throw l;
        }catch (Exception e){
            logger.error("登录供货价", e);
            throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_WLYC, "网络异常","loginSupply");
        }


    }

    @Override
    public boolean submitInformation(UserInformationVo vo) {
        boolean flag = false;
        User user = RedisDataTool.getRedisUserCache(vo.getAccessId(), redisUtil, true);
        user.setId(user.getId());
        user.setSignatory_type(vo.getSignatoryType());
        user.setSignatory_name(vo.getSignatoryName());
        user.setCompany_name(vo.getSignatoryName());
        user.setCompany_credit_code(vo.getCompanyCreditCode());
        user.setUser_name(vo.getUserName());
        user.setId_card(vo.getIdCard());
        user.setProvince(vo.getProvince());
        user.setCity(vo.getCity());
        user.setCounty(vo.getArea());
        user.setDetailed_address(vo.getDetailedAddress());
        user.setExamine_flag(GloabConst.UserExamineFlag.USER_EXAMINE_EXAMING);
        user.setSubmit_flag(GloabConst.UserSubmitFLag.USER_SUBMIT_FLAG_SUBMIT);
        int i = userBaseMapper.updateByPrimaryKeySelective(user);
        if(i > 0){
            flag = true;
        }else{
            throw new LaiKeAPIException("提交信息失败");
        }
        return flag;
    }

    @Override
    public UserBusinessInfoVo getBusinessInfo(MainVo vo) {
        UserBusinessInfoVo userBusinessInfoVo = new UserBusinessInfoVo();
        User user = RedisDataTool.getRedisUserCache(vo.getAccessId(), redisUtil);
        //判断是否有用户信息
        User newUser = new User();
        newUser.setUser_type(GloabConst.UserType.USER_TYPE_BUSINESS);
        newUser.setUser_id(user.getUser_id());
        user = userBaseMapper.selectOne(newUser);
        userBusinessInfoVo.setAccount(user.getZhanghao());
        userBusinessInfoVo.setIndustry(user.getIndustry());
        userBusinessInfoVo.setExamineFlag(user.getExamine_flag());
        userBusinessInfoVo.setUserType(user.getUser_type());
        userBusinessInfoVo.setSubmitFlag(user.getSubmit_flag());
        //审核通过
        if(user.getExamine_flag() == 1){
            UserBusinessInfo userBusinessInfo = new UserBusinessInfo();
            userBusinessInfo.setUserId(user.getUser_id());
            userBusinessInfo = userBusinessInfoMapper.selectOne(userBusinessInfo);
            userBusinessInfoVo.setDirector(userBusinessInfo.getSignatoryLegalPerson());
            userBusinessInfoVo.setSignTime(user.getSign_time());
            userBusinessInfoVo.setBusinessLicenseImg(userBusinessInfo.getBusinessLicenseImg());
            userBusinessInfoVo.setIdCardFaceImg(userBusinessInfo.getIdCardFaceImg());
            userBusinessInfoVo.setIdCardBackImg(userBusinessInfo.getIdCardBackImg());
            userBusinessInfoVo.setIdCard(userBusinessInfo.getSignatoryLegalPersonIdCard());
            userBusinessInfoVo.setSignatoryType(user.getSignatory_type());
            userBusinessInfoVo.setSignatoryName(user.getSignatory_name());
            userBusinessInfoVo.setCompanyCreditCode(user.getCompany_credit_code());
            userBusinessInfoVo.setUserName(userBusinessInfo.getSignatoryLegalPerson());
            userBusinessInfoVo.setProvince(user.getProvince());
            userBusinessInfoVo.setCity(user.getCity());
            userBusinessInfoVo.setArea(user.getCounty());
            userBusinessInfoVo.setDetailedAddress(user.getDetailed_address());
            userBusinessInfoVo.setBusinessDetailedAddress(userBusinessInfo.getAddress());
            userBusinessInfoVo.setExamineFlag(user.getExamine_flag());
        }
        return userBusinessInfoVo;
    }

    @Override
    public boolean submitBusinessInfo(UpdateUserBusinessInfoVo vo) throws Exception {
        boolean flag = false;
        User user = RedisDataTool.getRedisUserCache(vo.getAccessId(), redisUtil, true);
        User newUser = new User();
        newUser.setId(user.getId());
        user = userBaseMapper.selectOne(newUser);
        user.setId(user.getId());
        if(StringUtil.isNotBlank(vo.getProvince())){
            user.setProvince(vo.getProvince());
        }
        if(StringUtil.isNotBlank(vo.getCity())){
            user.setCity(vo.getCity());
        }
        if(StringUtil.isNotBlank(vo.getArea())){
            user.setCounty(vo.getArea());
        }
        if(StringUtil.isNotBlank(vo.getDetailedAddress())){
            user.setDetailed_address(vo.getDetailedAddress());
        }
        user.setIndustry(vo.getIndustry());
        //审核通过不修改工商信息
        if(!GloabConst.UserExamineFlag.USER_EXAMINE_PASS.equals(user.getExamine_flag())){
            //校验营业执照三要素
            VerifyBusinessData businessData = verifyService.verifyBusinessLicense(vo.getCompanyCreditCode(), vo.getSignatoryName(), vo.getUserName());
            boolean sameFlag = businessData.isData();
            if(!sameFlag){
                throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERRCODE_BUSINESSNOTSANME,"法人姓名与工商信息不一致");
            }

            user.setSignatory_type(vo.getSignatoryType());
            user.setSignatory_name(vo.getSignatoryName());
            user.setCompany_name(vo.getSignatoryName());
            user.setCompany_credit_code(vo.getCompanyCreditCode());
            user.setUser_name(vo.getUserName());
            user.setId_card(vo.getIdCard());
            user.setId_card_face_img(vo.getIdCardFaceImg());
            user.setId_card_back_img(vo.getIdCardBackImg());
            user.setBusiness_license_img(vo.getBusinessLicenseImg());
            user.setExamine_flag(GloabConst.UserExamineFlag.USER_EXAMINE_EXAMING);
            user.setSubmit_flag(GloabConst.UserSubmitFLag.USER_SUBMIT_FLAG_SUBMIT);
        }
        int i = userBaseMapper.updateByPrimaryKeySelective(user);
        if(i > 0){
            flag = true;
        }else{
            throw new LaiKeAPIException("提交信息失败");
        }
        return flag;
    }


    @DubboApiMethod(apiKey = "com.laike.user.loginSms",
            login = false, module = UserConst.MODULE_NAME, version = "1.0.0")
    @Override
    public Map<String, Object> loginSms(MainVo vo, String phone, String pcode, String pid, String clientid) throws LaiKeAPIException {
        Map<String, Object> resultMap = new HashMap<>(16);
        try {
            String loginKey = GloabConst.RedisHeaderKey.LOGIN_HEADER + phone;
            //检测手机号格式
            if (!MobileUtils.isMobile(phone)) {
                throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_SJHGSBZQ, "手机号格式不正确");
            }
            //公告id
            Integer tell_id = 0;
            //公告标题
            String systemMsgTitle = "";
            //系统公告
            String systemMsg = "";
            //公告类型 1=系统维护 2=升级公告 3-- 普通公告
            int systemMsgType = 0;
            //维护开始、结束时间
            String systemMsgStartDate = "";
            String systemMsgEndDate = "";
            //验证
            if (redisUtil.hasKey(loginKey)) {
                String rpcode = redisUtil.get(loginKey).toString();
                if (rpcode.equals(pcode)) {
                    //用户是否存在,不存在则注册
                    User userResult = new User();
                    userResult.setStore_id(vo.getStoreId());
                    userResult.setMobile(phone);
                    userResult = userBaseMapper.selectOne(userResult);
                    if (userResult == null) {
                        userResult = new User();
                        userResult.setMobile(phone);
                        userResult.setMima("");
                        userResult.setZhanghao(phone);
                        //校验数据格式
                        userResult = DataCheckTool.checkUserDataFormate(userResult);
                        //注册
                        publicUserService.register(vo, pid, userResult);
                    } else {
                        userResult.setReferee(pid);
                        userResult.setAccess_id(vo.getAccessId());
                    }
                    if (DictionaryConst.StoreSource.LKT_LY_001.equals(vo.getStoreType() + "")) {
                        int wxStatus = 0;
                        if (!StringUtils.isEmpty(userResult.getWx_id())) {
                            wxStatus = 1;
                        }
                        resultMap.put("wx_status", wxStatus);
                    }
                    //登录成功流程
                    publicUserService.loginSuccess(userResult, userResult.getAccess_id(), pid);
                    //移除验证码
                    redisUtil.del(loginKey);

                    int isPwd = 0;
                    if (!StringUtils.isEmpty(userResult.getMima())) {
                        isPwd = 1;
                    }
                    Map<String, Object> parmaMap = new HashMap<>(16);
                    parmaMap.put("store_id", 0);
                    parmaMap.put("startDate_lt", new Date());
                    parmaMap.put("endDate_gt", new Date());
                    parmaMap.put("type_sort", DataUtils.Sort.ASC.toString());
                    parmaMap.put("user_tell", SystemTellModel.TELL.YES);
                    parmaMap.put("user_store_id", vo.getStoreId());
                    parmaMap.put("store_type", vo.getStoreType());
                    parmaMap.put("read_id", userResult.getUser_id());
                    List<Map<String, Object>> systemList = systemTellModelMapper.selectDynamic(parmaMap);
                    if (systemList.size() > 0) {
                        Map<String, Object> systemMap = systemList.get(0);
                        systemMsgTitle = MapUtils.getString(systemMap, "title");
                        systemMsg = MapUtils.getString(systemMap, "content");
                        systemMsgType = MapUtils.getIntValue(systemMap, "type");
                        tell_id = MapUtils.getInteger(systemMap, "id");
                        systemMsgEndDate = DateUtil.dateFormate(MapUtils.getString(systemMap, "enddate"), GloabConst.TimePattern.YMDHMS);
                        systemMsgStartDate = DateUtil.dateFormate(MapUtils.getString(systemMap, "startdate"), GloabConst.TimePattern.YMDHMS);
                    }
                    String info = "登录成功";
                    if (systemMsgType == 1){
                        info = "系统维护中";
                    }
                    //系统公告
                    resultMap.put("systemMsgTitle", systemMsgTitle);
                    resultMap.put("systemMsg", systemMsg);
                    resultMap.put("systemMsgType", systemMsgType);
                    resultMap.put("tell_id", tell_id);
                    resultMap.put("systemMsgEndDate", systemMsgEndDate);
                    resultMap.put("systemMsgStartDate", systemMsgStartDate);
                    resultMap.put("info", info);
                    resultMap.put("y_password", isPwd);
                    resultMap.put("access_id", userResult.getAccess_id());
                    resultMap.put("user_name", userResult.getUser_name());
                    resultMap.put("headimgurl", userResult.getHeadimgurl());
                    resultMap.put("lang", userResult.getLang());
                } else {
                    throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_YZMBZQ, "验证码不正确", "loginSms");
                }
            } else {
                throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_QZXHQYZM, "请重新获取验证码", "loginSms");
            }
        } catch (LaiKeAPIException l) {
            throw l;
        } catch (Exception e) {
            logger.error("短信登录 异常 ", e);
            throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_WLYC, "网络异常", "loginSms");
        }
        return resultMap;
    }

    @DubboApiMethod(apiKey = "com.laike.user.updateUser",
            login = true, module = UserConst.MODULE_NAME, version = "1.0.0")
    @Override
    public boolean updateUser(MainVo vo, Integer sex, String birthday, String nickname, MultipartFile file) throws LaiKeAPIException {
        try {
            User updateUser;
            User userCache = RedisDataTool.getRedisUserCache(vo.getAccessId(), redisUtil, true);

            User user = new User();
            if (!StringUtils.isEmpty(birthday)) {
                user.setBirthday(DateUtil.dateFormateToDate(birthday, GloabConst.TimePattern.YMD));
                user.setIs_default_birthday(2);
            }
            user.setUser_name(nickname);
            if (sex != null) {
                user.setSex(sex);
            }

            //校验数据格式
            updateUser = DataCheckTool.checkUserDataFormate(user);

            User userTemp = new User();
            userTemp.setId(userCache.getId());
            userCache = userBaseMapper.selectOne(userTemp);

            updateUser.setId(userCache.getId());
/*            //生日只允许修改一次
            if (updateUser.getBirthday() != null && userCache.getBirthday() != null) {
                throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_CSRQZNXGYC, "出生日期只能修改一次", "updateUser");
            }*/
            updateUser.setIs_default_value(2);
            //头像上传 头像上传用oss
            if (file != null && !file.isEmpty()) {
                MultipartFile[] files = new MultipartFile[]{file};
                List<String> reusltUrl = uploadImage(vo.getStoreId(), vo.getStoreType(), GloabConst.UploadConfigConst.IMG_UPLOAD_OSS, files);
                if (reusltUrl != null && !reusltUrl.isEmpty()) {
                    updateUser.setHeadimgurl(ImgUploadUtils.getUrlPure(reusltUrl.get(0), true));
                } else {
                    throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_WLFMQSHZS, "网络繁忙,请稍后再试", "updateUser");
                }
            }

            //修改用户资料
            int count;
            try {
                count = userBaseMapper.updateByPrimaryKeySelective(updateUser);
                if (count > 0) {
                    //更新缓存
                    User user1 = userBaseMapper.selectByPrimaryKey(userCache.getId());
                    RedisDataTool.refreshRedisUserCache(vo.getAccessId(), user1, redisUtil);
                    return true;
                }
            } catch (Exception e) {
                e.printStackTrace();
                throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_WLFMQSHZS, "网络繁忙,请稍后再试", "updateUser");
            }
            throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_WLFMQSHZS, "网络繁忙,请稍后再试", "updateUser");
        } catch (LaiKeAPIException l) {
            throw l;
        } catch (Exception e) {
            logger.error("修改用户资料 异常 ", e);
            throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_WLYC, "网络异常", "updateUser");
        }
    }

    @DubboApiMethod(apiKey = "com.laike.user.uploadImage",
            login = true, module = UserConst.MODULE_NAME, version = "1.0.0")
    @Override
    public List<String> uploadImage(int storeId, int storeType, String uploadType, MultipartFile[] files) throws LaiKeAPIException {
        try {
            if (files == null || files.length < 1) {
                throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_QXZXYSCDTP, "请选择需要上传的图片", "updateUser");
            }
            //获取商城配置信息
            ConfigModel configModel = new ConfigModel();
            configModel.setStore_id(storeId);
            configModel = configModelMapper.selectOne(configModel);
            if (configModel != null) {
                uploadType = configModel.getUpserver();
            }
            //图片上传
            return publiceService.uploadImage(DataUtils.convertToList(files), uploadType, storeType, storeId);
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("密码修改异常 " + e.getMessage());
            throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_TPSCSB, "图片上传失败", "uploadImage");
        }
    }


    @DubboApiMethod(apiKey = "com.laike.user.updatePassword",
            login = true, module = UserConst.MODULE_NAME, version = "1.0.0")
    @Override
    public boolean updatePassword(MainVo vo, String password, String newPwd, String confirm) throws LaiKeAPIException {
        try {
            User user;
            if (!StringUtils.isEmpty(vo.getAccessId())) {
                user = RedisDataTool.getRedisUserCache(vo.getAccessId(), redisUtil);
                if (user != null) {
                    String mima = CryptoUtil.strDecode(user.getMima());
                    if (!password.equals(mima)) {
                        throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_YMMBZQ, "原密码不正确");
                    }
                    if (newPwd.equals(password)) {
                        throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_XMMHJMMXT, "新密码和旧密码相同");
                    }
                    if (!confirm.equals(newPwd)) {
                        throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_QRMMYXMMXYZ, "确认密码与新密码需一致");
                    }
                    User userParma = new User();
                    userParma.setId(user.getId());
                    userParma.setMima(CryptoUtil.strEncode(newPwd));
                    int count = userBaseMapper.updateByPrimaryKeySelective(userParma);
                    if (count < 1) {
                        logger.debug("用户id=" + user.getId() + " 密码修改失败");
                    } else {
                        //重置登陆缓存
                        user = userBaseMapper.selectByPrimaryKey(user.getId());
                        RedisDataTool.refreshRedisUserCache(vo.getAccessId(), user, redisUtil);
                        return true;
                    }
                } else {
                    throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_QDL, "请登录");
                }
            } else {
                throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_CSCW, "参数错误", "updatepassword");
            }
        } catch (LaiKeAPIException l) {
            throw l;
        } catch (Exception e) {
            logger.error("密码修改异常 ", e);
            throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_WLYC, "网络异常", "updatepassword");
        }
        return false;
    }

    @DubboApiMethod(apiKey = "com.laike.user.set_payment_password",
            login = true, module = UserConst.MODULE_NAME, version = "1.0.0")
    @Override
    public void setPaymentPassword(MainVo vo, String password, String keyCode) throws LaiKeAPIException {
        try {
            User user = null;
            if (!StringUtils.isEmpty(vo.getAccessId())) {
                user = RedisDataTool.getRedisUserCache(vo.getAccessId(), redisUtil, true);
                user = userBaseMapper.selectByPrimaryKey(user.getId());
                publiceService.validatePhoneCode(GloabConst.RedisHeaderKey.UPDATE_PWD_PAY_CODE, user.getMobile(), keyCode);
                String currentPwd = user.getPassword();
                if (StringUtils.isNotEmpty(currentPwd)) {
                    throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_MMYSZ, "密码已设置");
                }
                String updatePwd = password;
                User userParma = new User();
                userParma.setId(user.getId());
                userParma.setPassword(updatePwd);
                //校验密码格式
                DataCheckTool.checkUserDataFormate(userParma);
                updatePwd = Md5Util.MD5endoce(updatePwd);
                userParma.setPassword(updatePwd);
                int count = userBaseMapper.updateUserInfoById(userParma);
                if (count < 1) {
                    logger.debug("用户id=" + user.getId() + " 支付密码设置失败");
                    throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_MMSZSB, "密码设置失败");
                }
                //重置登陆缓存
                RedisDataTool.refreshRedisUserCache(user, redisUtil);
            } else {
                throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_CSCW, "参数错误", "updatePaymentPassword");
            }
        } catch (LaiKeAPIException l) {
            throw l;
        } catch (Exception e) {
            logger.error("密码修改异常 ", e);
            throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_WLYC, "网络异常", "updatePaymentPassword");
        }
    }

    @DubboApiMethod(apiKey = "com.laike.user.getUserSet",
            login = true, module = UserConst.MODULE_NAME, version = "1.0.0")
    @Override
    public Map<String, Object> set(MainVo vo) throws LaiKeAPIException {
        Map<String, Object> resultMap = new HashMap<>(16);
        //是否设置支付密码
        int passwordStatus = 0;
        //登陆密码
        int mimaStatus = 0;
        try {
            User user = null;
            if (!StringUtils.isEmpty(vo.getAccessId())) {
                Object userObj = redisUtil.get(GloabConst.RedisHeaderKey.LOGIN_ACCESS_TOKEN + vo.getAccessId());
                if (userObj != null) {
                    user = JSON.parseObject(userObj.toString(), User.class);
                    if (!StringUtils.isEmpty(user.getPassword())) {
                        passwordStatus = 1;
                    }
                    if (!StringUtils.isEmpty(user.getMima())) {
                        mimaStatus = 1;
                    }
                }
                resultMap.put("password_status", passwordStatus);
                resultMap.put("mima_status", mimaStatus);
            }

        } catch (LaiKeAPIException l) {
            throw l;
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("获取设置异常 " + e.getMessage());
            throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_WLYC, "网络异常", "set");
        }
        return resultMap;
    }

    @DubboApiMethod(apiKey = "com.laike.user.validatePaymentPWD",
            login = true, module = UserConst.MODULE_NAME, version = "1.0.0")
    @Override
    public boolean paymentPassword(MainVo vo, String password) throws LaiKeAPIException {
        try {
            User cashUser = RedisDataTool.getRedisUserCache(vo.getAccessId(), redisUtil, true);
            publicUserService.validatePayPwd(cashUser.getUser_id(), password);
            return true;
        } catch (LaiKeAPIException l) {
            throw l;
        } catch (Exception e) {
            logger.error("验证支付密码异常 ", e);
            throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_WLYC, "网络异常", "paymentPassword");
        }
    }

    @DubboApiMethod(apiKey = "com.laike.user.getUserWallet",
            login = true, module = UserConst.MODULE_NAME, version = "1.0.0")
    @Override
    public Map<String, Object> getUserWallet(MainVo vo) throws LaiKeAPIException {
        Map<String, Object> resultMap = new HashMap<>(16);
        try {
            //可提现状态
            int status = 0;
            //钱包单位
            String unit = "元";
            User user = new User();
            if (!StringUtils.isEmpty(vo.getAccessId())) {
                user = RedisDataTool.getRedisUserCache(vo.getAccessId(), redisUtil, false);
                if (user != null) {
                    //多端登录，重置用户信息
                    user = userBaseMapper.selectByUserId(vo.getStoreId(), user.getUser_id());
                    //获取钱包明细第一页数据
                    resultMap.putAll(getUserWalletDetail(vo, null));
                    //获取可提现数量
                    WithdrawModel withdrawModel = new WithdrawModel();
                    withdrawModel.setStore_id(vo.getStoreId());
                    withdrawModel.setUser_id(user.getUser_id());
                    withdrawModel.setStatus("0");
                    withdrawModel.setIs_mch(0);
                    int withdrawalNum = withdrawModelMapper.selectCount(withdrawModel);
                    if (withdrawalNum > 0) {
                        status = 1;
                    }
                    //查询钱包单位
                    FinanceConfigModel financeConfigModel = new FinanceConfigModel();
                    financeConfigModel.setStore_id(vo.getStoreId());
                    financeConfigModel = financeConfigModelMapper.selectOne(financeConfigModel);
                    if (financeConfigModel != null) {
                        unit = financeConfigModel.getUnit();
                    }

                    resultMap.put("unit", unit);
                    //保留两位小数
                    resultMap.put("user_money", user.getMoney().setScale(2,BigDecimal.ROUND_HALF_UP).toString());
                    resultMap.put("status", status);
                }
            }
        } catch (LaiKeAPIException l) {
            throw l;
        } catch (Exception e) {
            logger.error("获取我的钱包信息异常 ", e);
            throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_WLYC, "网络异常", "getUserWallet");
        }
        return resultMap;
    }


    @DubboApiMethod(apiKey = "com.laike.user.wallet_detailed",
            login = true, module = UserConst.MODULE_NAME, version = "1.0.0")
    @Override
    public Map<String, Object> getUserWalletDetail(MainVo vo, Integer type) throws LaiKeAPIException {
        Map<String, Object> resultMap = new HashMap<>(16);
        try {
            User user = RedisDataTool.getRedisUserCache(vo.getAccessId(), redisUtil, true);
            Map<String, Object> parmaMap = new HashMap<>(16);
            parmaMap.put("store_id", vo.getStoreId());
            parmaMap.put("userid", user.getUser_id());
            List<Integer> list = new ArrayList<>();
            if (type != null && type != 0) {
                if (type == 1) {
                    list.addAll(RecordModel.TYPE_RECHARGE);
                    list.add(RecordModel.RecordType.REFUND_MCH_BOND);
                    list.add(RecordModel.RecordType.REFUND);
                    list.add(RecordModel.RecordType.WITHDRAWAL_FAILED);
                    parmaMap.put("typeList", list);
                } else {
                    list.add(RecordModel.RecordType.APPLICATION_FOR_WITHDRAWAL);
                    list.add(RecordModel.RecordType.WITHDRAWAL_SUCCEED);
                    list.add(RecordModel.RecordType.PAY_MCH_DEPOSIT);
                    list.add(RecordModel.RecordType.BALANCE_CONSUMPTION);
                    list.add(RecordModel.RecordType.SYSTEM_DEDUCTION);
                    parmaMap.put("typeList", list);
                }
            } else {
                list.addAll(RecordModel.TYPE_RECHARGE);
                list.addAll(RecordModel.TYPE_CASH_WITHDRAWAL);
                list.add(RecordModel.RecordType.REFUND_MCH_BOND);
                list.add(RecordModel.RecordType.BALANCE_CONSUMPTION);
                list.add(RecordModel.RecordType.REFUND);
                list.add(RecordModel.RecordType.SYSTEM_DEDUCTION);
                list.add(RecordModel.RecordType.PAY_MCH_DEPOSIT);
                parmaMap.put("typeList", list);
            }
            parmaMap.put("pageStart", vo.getPageNo());
            parmaMap.put("pageEnd", vo.getPageSize());


            List<Map<String, Object>> myWalletInfoList = recordModelMapper.getUserWalletRecordInfo(parmaMap);
            for (Map<String, Object> map : myWalletInfoList) {
                Date addDate = (Date) map.get("add_date");
                String time = DateUtil.dateFormate(addDate, GloabConst.TimePattern.YMDHMS);
                map.put("add_date", time);
                map.put("money", new BigDecimal(map.get("money").toString()).abs().toString());
            }
            resultMap.put("list", myWalletInfoList);
        } catch (LaiKeAPIException l) {
            throw l;
        } catch (Exception e) {
            logger.error("我的钱包加载更多异常 ", e);
            throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_WLYC, "网络异常", "getUserWalletDetail");
        }
        return resultMap;
    }


    @DubboApiMethod(apiKey = "com.laike.user.set_password",
            login = true, module = UserConst.MODULE_NAME, version = "1.0.0")
    @Override
    public boolean setPassword(MainVo vo, String password, String phone, String keyCode) throws LaiKeAPIException {
        try {
            User user = RedisDataTool.getRedisUserCache(vo.getAccessId(), redisUtil, true);
            //校验验证码
            boolean validateSms = publiceService.validatePhoneCode(GloabConst.RedisHeaderKey.UPDATE_PASSWORDE, phone, keyCode);
            if (validateSms) {
                String updatePwd = password;
                User userParma = new User();
                userParma.setId(user.getId());
                userParma.setMima(updatePwd);
                DataCheckTool.checkUserDataFormate(userParma);
                updatePwd = CryptoUtil.strEncode(updatePwd);
                userParma.setMima(updatePwd);
                int count = userBaseMapper.updateUserInfoById(userParma);
                if (count < 1) {
                    logger.debug("用户id=" + user.getId() + " 密码修改失败");
                } else {
                    //清除短信
                    redisUtil.del(GloabConst.RedisHeaderKey.UPDATE_PASSWORDE + phone);
                    //重置缓存
                    user = userBaseMapper.selectByPrimaryKey(user.getId());
                    RedisDataTool.refreshRedisUserCache(vo.getAccessId(), user, redisUtil);
                    return true;
                }
            }
        } catch (LaiKeAPIException l) {
            throw l;
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("设置登陆密码异常 " + e.getMessage());
            throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_WLYC, "网络异常", "setPassword");
        }
        return false;
    }

    @DubboApiMethod(apiKey = "com.laike.user.modify_payment_password",
            login = true, module = UserConst.MODULE_NAME, version = "1.0.0")
    @Override
    public boolean updatePayPassword(MainVo vo, String password, String phone, String keyCode) throws LaiKeAPIException {
        try {
            User user = null;
            if (!StringUtils.isEmpty(vo.getAccessId())) {
                Object userObj = redisUtil.get(GloabConst.RedisHeaderKey.LOGIN_ACCESS_TOKEN + vo.getAccessId());
                if (userObj != null) {
                    //校验验证码
                    boolean validateSms = publiceService.validatePhoneCode(GloabConst.RedisHeaderKey.UPDATE_PWD_PAY_CODE, phone, keyCode);
                    if (validateSms) {
                        user = JSON.parseObject(userObj.toString(), User.class);
                        String currentPwd = user.getPassword();
                        String updatePwd = password;
                        User userParma = new User();
                        userParma.setId(user.getId());
                        userParma.setPassword(updatePwd);
                        DataCheckTool.checkUserDataFormate(userParma);
                        updatePwd = Md5Util.MD5endoce(updatePwd);
                        if (currentPwd.equals(updatePwd)) {
                            throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_MMWBH, "密码未变化", "updatePayPassword");
                        }
                        userParma.setPassword(updatePwd);
                        int count = userBaseMapper.updateUserInfoById(userParma);
                        if (count < 1) {
                            logger.debug("用户id=" + user.getId() + " 支付密码修改失败");
                        } else {
                            //清除短信缓存
                            redisUtil.del(GloabConst.RedisHeaderKey.UPDATE_PWD_PAY_CODE + phone);
                            //获取登录生命周期
                            Integer lifeTile = publicUserService.getUserLoginLife(vo.getStoreId());
                            //重置登陆缓存
                            user.setPassword(updatePwd);
                            redisUtil.set(GloabConst.RedisHeaderKey.LOGIN_ACCESS_TOKEN + user.getAccess_id(), JSON.toJSONString(user), lifeTile);
                            return true;
                        }
                    }
                }
            } else {
                throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_CSCW, "参数错误", "updatePayPassword");
            }
        } catch (LaiKeAPIException l) {
            throw l;
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("修改支付密码 " + e.getMessage());
            throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_WLYC, "网络异常", "updatePayPassword");
        }
        return false;
    }

    @DubboApiMethod(apiKey = "com.laike.user.update_phone",
            login = true, module = UserConst.MODULE_NAME, version = "1.0.0")
    @Override
    public boolean updatePhone(MainVo vo, String phoneNew, String keyCode) throws LaiKeAPIException {
        try {
            User user;
            if (!StringUtils.isEmpty(vo.getAccessId())) {
                user = RedisDataTool.getRedisUserCache(vo.getAccessId(), redisUtil);
                if (user != null) {
                    if (StringUtils.isEmpty(phoneNew)) {
                        throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_SJHBNWK, "手机号不能为空");
                    }
                    if (phoneNew.equals(user.getMobile())) {
                        throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_XSJHBNHJSJXT, "新手机号不能和旧手机相同");
                    }
                    //校验验证码
                    publiceService.validatePhoneCode(GloabConst.RedisHeaderKey.UPDATE_PHOE_CODE, phoneNew, keyCode);
                    User userParma = new User();
                    userParma.setId(user.getId());
                    userParma.setMobile(phoneNew);
                    DataCheckTool.checkUserDataFormate(userParma);
                    //校验手机号是否已被注册
                    int count = userBaseMapper.validataUserPhoneOrNoIsRegister(vo.getStoreId(), phoneNew);
                    if (count > 0) {
                        throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_SJHYBZC, "手机号已被注册");
                    }
                    count = userBaseMapper.updateUserInfoById(userParma);
                    if (count < 1) {
                        logger.debug("用户id=" + user.getId() + " 密码修改失败");
                        throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_CSCW, "参数错误");
                    }
                    //清除短信缓存
                    redisUtil.del(GloabConst.RedisHeaderKey.UPDATE_PHOE_CODE + phoneNew);
                    //重置登陆缓存
                    user = userBaseMapper.selectByPrimaryKey(user.getId());
                    RedisDataTool.refreshRedisUserCache(vo.getAccessId(), user, redisUtil);
                    return true;
                }
            } else {
                throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_CSCW, "参数错误", "updatePhone");
            }
        } catch (LaiKeAPIException l) {
            throw l;
        } catch (Exception e) {
            logger.error("修改手机号异常 ", e);
            throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_WLYC, "网络异常", "updatePhone");
        }
        return false;
    }

    @DubboApiMethod(apiKey = "com.laike.user.about_us",
            login = true, module = UserConst.MODULE_NAME, version = "1.0.0")
    @Override
    public Map<String, Object> aboutUs(MainVo vo) throws LaiKeAPIException {
        Map<String, Object> resultMap = new HashMap<>(16);
        String aboutus = "";
        try {
            ConfigModel configModel = new ConfigModel();
            configModel.setStore_id(vo.getStoreId());
            configModel = configModelMapper.selectOne(configModel);
            if (configModel != null) {
                aboutus = configModel.getAboutus();
            }
//            aboutus = XssUtil.stripXSS(aboutus);
            resultMap.put("aboutus", aboutus);
        } catch (LaiKeAPIException l) {
            throw l;
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("获取关于我们异常 " + e.getMessage());
            throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_WLYC, "网络异常", "aboutUs");
        }
        return resultMap;
    }

    @DubboApiMethod(apiKey = "com.laike.user.into_wallet1",
            login = true, module = UserConst.MODULE_NAME, version = "1.0.0")
    @Override
    public Map<String, Object> intoWallet1(MainVo vo, Integer shopId, String pluginType) throws LaiKeAPIException {
        Map<String, Object> resultMap;
        try {
            User user = RedisDataTool.getRedisUserCache(vo.getAccessId(), redisUtil, true);
            resultMap = publicUserService.getIntoWallet(vo, shopId, user, pluginType);
        } catch (LaiKeAPIException l) {
            throw l;
        } catch (Exception e) {
            logger.error("获取提现信息异常 ", e);
            throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_WLYC, "网络异常", "intoWallet1");
        }
        return resultMap;
    }


    @DubboApiMethod(apiKey = "com.laike.user.withdrawals1",
            login = true, module = UserConst.MODULE_NAME, version = "1.0.0")
    @Transactional(rollbackFor = Exception.class)
    @Override
    public Map<String, Object> withdrawals1(Withdrawals1Vo vo) throws LaiKeAPIException {
        Map<String, Object> resultMap = new HashMap<>(16);
        try {
            User user = RedisDataTool.getRedisUserCache(vo.getAccessId(), redisUtil, true);
            if (vo.getWithdrawStatus().equals(WithdrawModel.WITHDRAW_STATUS.YHK)){
                //校验验证码
                publiceService.validatePhoneCode(GloabConst.RedisHeaderKey.DRAWING_CODE, vo.getMobile(), vo.getKeyCode());
            }
            if (!publiceService.withdrawals(vo, user)) {
                logger.warn("提现记录失败");
                throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_TXSBQSHZS_001, "提现失败,请稍后重试");
            }
            MchModel mchModel = mchModelMapper.selectByPrimaryKey(user.getMchId());
            //删除短信
            redisUtil.del(GloabConst.RedisHeaderKey.DRAWING_CODE + vo.getMobile());
            WithdrawModel withdrawOld = new WithdrawModel();
            MessageLoggingModal messageLoggingSave = new MessageLoggingModal();
            if (vo.getShopId() != null) {
                withdrawOld = withdrawModelMapper.getWithdrawInfoByUserId(user.getUser_id(), DictionaryConst.WhetherMaven.WHETHER_OK);
                messageLoggingSave.setMch_id(user.getMchId());
                messageLoggingSave.setStore_id(vo.getStoreId());
                messageLoggingSave.setType(MessageLoggingModal.Type.TYPE_STORE_WITHDRAWAL);
                messageLoggingSave.setTo_url(MessageLoggingModal.AdminUrl.STORE_WITHDRAWAL_URL);
                messageLoggingSave.setParameter(mchModel.getName());
                messageLoggingSave.setContent(String.format("ID为%s的店铺申请提取余额，请及时处理！",mchModel.getId()));
                messageLoggingSave.setAdd_date(new Date());
                messageLoggingModalMapper.insertSelective(messageLoggingSave);
                //h5店铺消息通知(您的店铺提现申请已提交成功，正在等待管理员审核！)
                messageLoggingSave = new MessageLoggingModal();
                messageLoggingSave.setMch_id(user.getMchId());
                messageLoggingSave.setStore_id(vo.getStoreId());
                messageLoggingSave.setType(MessageLoggingModal.Type.TYPE_H5MCH_WITHDRAWAL_APPLICATION_SUCCESSFULLY_SUBMITTED);
                messageLoggingSave.setTo_url("");
                messageLoggingSave.setParameter("提现申请已提交");
                messageLoggingSave.setContent("您的店铺提现申请已提交成功，正在等待管理员审核！");
                messageLoggingSave.setAdd_date(new Date());
                messageLoggingModalMapper.insertSelective(messageLoggingSave);
                //pc店铺消息通知(您的店铺提现申请已提交成功，正在等待管理员审核！)
                messageLoggingSave = new MessageLoggingModal();
                messageLoggingSave.setMch_id(user.getMchId());
                messageLoggingSave.setStore_id(vo.getStoreId());
                messageLoggingSave.setType(MessageLoggingModal.Type.TYPE_MCH_WITHDRAWAL_APPLICATION_SUCCESSFULLY_SUBMITTED);
                messageLoggingSave.setTo_url(MessageLoggingModal.PcMchUrl.WITHDRAWAL_APPLICATION_SUCCESSFULLY_SUBMITTED);
                messageLoggingSave.setParameter("");
                messageLoggingSave.setContent("您的店铺提现申请已提交成功，正在等待管理员审核！");
                messageLoggingSave.setAdd_date(new Date());
                messageLoggingModalMapper.insertSelective(messageLoggingSave);
            } else {
                withdrawOld = withdrawModelMapper.getWithdrawInfoByUserId(user.getUser_id(), DictionaryConst.WhetherMaven.WHETHER_NO);
                if (StringUtils.isNotEmpty(vo.getPluginType())){
                    if (vo.getPluginType().equals(DictionaryConst.OrdersType.ORDERS_HEADER_FX)){
                        messageLoggingSave.setMch_id(user.getMchId());
                        messageLoggingSave.setStore_id(vo.getStoreId());
                        messageLoggingSave.setType(MessageLoggingModal.Type.TYPE_USER_WITHDRAWAL);
                        messageLoggingSave.setTo_url(MessageLoggingModal.AdminUrl.USER_DISTRIBUTION_WITHDRAWAL_URL);
                        messageLoggingSave.setParameter(user.getUser_name());
                        messageLoggingSave.setContent(String.format("ID为%s的分销商申请提取余额，请及时处理！", user.getUser_id()));
                        messageLoggingSave.setAdd_date(new Date());
                    }
                }else {
                    messageLoggingSave.setMch_id(user.getMchId());
                    messageLoggingSave.setStore_id(vo.getStoreId());
                    messageLoggingSave.setType(MessageLoggingModal.Type.TYPE_USER_WITHDRAWAL);
                    messageLoggingSave.setTo_url(MessageLoggingModal.AdminUrl.USER_WITHDRAWAL_URL);
                    messageLoggingSave.setParameter(user.getUser_name());
                    messageLoggingSave.setContent(String.format("ID为%s的用户申请提取余额，请及时处理！", user.getUser_id()));
                    messageLoggingSave.setAdd_date(new Date());
                }
                messageLoggingModalMapper.insertSelective(messageLoggingSave);
            }
            resultMap.put("addDate", DateUtil.dateFormate(new Date(), GloabConst.TimePattern.YMDHMS));
        } catch (LaiKeAPIException l) {
            throw l;
        } catch (Exception e) {
            logger.error("申请提现异常 ", e);
            throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_WLYC, "网络异常", "withdrawals1");
        }
        return resultMap;
    }


    @DubboApiMethod(apiKey = "com.laike.user.VerificationBank",
            login = true, module = UserConst.MODULE_NAME, version = "1.0.0")
    @Override
    public Map<String, Object> verificationBank(MainVo vo, String bankName, String bankCardNumber) throws LaiKeAPIException {
        Map<String, Object> resultMap = new HashMap<>(16);
        try {
            //是否为数字
            if (!bankTool.isNumber(bankCardNumber)) {
                throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_YXKGSCW, "银行卡格式错误");
            }
            //获取银行名称
            String name = bankTool.getBankNameByNo(bankCardNumber);
            if (StringUtils.isEmpty(name)) {
                throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_YXKGSCW, "银行卡格式错误");
            } else {
                name = name.substring(0, name.indexOf("-"));
                resultMap.put("Bank_name", name);
                if (!com.laiketui.core.diyJavaFunction.StringUtils.isEmpty(bankName)) {
                    if (!name.equals(bankName)) {
                        throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_YXKXXBPP, "银行卡信息不匹配");
                    }
                }
            }
        } catch (LaiKeAPIException l) {
            throw l;
        } catch (Exception e) {
            logger.error("校验银行卡异常 ", e);
            throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_WLYC, "网络异常", "verificationBank");
        }
        return resultMap;
    }

    @Override
    public List<Map<String, Object>> bankList(MainVo vo) throws LaiKeAPIException {
        List<Map<String, Object>> bankInfoList = new ArrayList<>();
        try {
            User user = RedisDataTool.getRedisUserCache(vo.getAccessId(), redisUtil, true);
            //获取客户银行卡信息
            List<BankCardModel> bankCardModelList = bankCardModelMapper.selectBankcardByUser(vo.getStoreId(), user.getUser_id());
            for (BankCardModel bankCard : bankCardModelList) {
                Map<String, Object> bankMap = new HashMap<>(16);
                bankMap.put("id", bankCard.getId());
                bankMap.put("Bank_name", bankCard.getBank_name());
                String bankNo = bankCard.getBank_card_number();
                bankMap.put("Bank_card_number", bankNo.substring(bankNo.length() - 4));
                bankMap.put("branchName", bankCard.getBranch());
                bankInfoList.add(bankMap);
            }
        } catch (LaiKeAPIException l) {
            throw l;
        } catch (Exception e) {
            logger.error("获取我的银行卡列表 ", e);
            throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_WLYC, "网络异常", "bankList");
        }
        return bankInfoList;
    }

    @Override
    public Map<String, Object> getBankDetail(MainVo vo, int bankId) throws LaiKeAPIException {
        Map<String, Object> resultMap = new HashMap<>(16);
        try {
            User user = RedisDataTool.getRedisUserCache(vo.getAccessId(), redisUtil, true);
            //获取客户银行卡信息
            BankCardModel bankCardModel = bankCardModelMapper.selectByPrimaryKey(bankId);
            if (bankCardModel == null) {
                throw new LaiKeAPIException(ErrorCode.BizErrorCode.DATA_NOT_EXIST, "银行卡不存在");
            }
            if (!user.getUser_id().equals(bankCardModel.getUser_id())) {
                throw new LaiKeAPIException(ErrorCode.BizErrorCode.ILLEGAL_INVASION, "非法入侵");
            }

            resultMap.put("cardholder", bankCardModel.getCardholder());
            resultMap.put("cardNo", bankCardModel.getBank_card_number());
            resultMap.put("bankName", bankCardModel.getBank_name());
            resultMap.put("branchName", bankCardModel.getBranch());
            resultMap.put("isDefault", bankCardModel.getIs_default());
        } catch (LaiKeAPIException l) {
            throw l;
        } catch (Exception e) {
            logger.error("获取银行卡详情 ", e);
            throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_WLYC, "网络异常", "getBankDetail");
        }
        return resultMap;
    }

    @Transactional(rollbackFor = Exception.class)
    @DubboApiMethod(apiKey = "com.laike.user.addBank",
            login = true, module = UserConst.MODULE_NAME, version = "1.0.0")
    @Override
    public boolean addBank(AddBankVo vo) throws LaiKeAPIException {
        try {
            User user = RedisDataTool.getRedisUserCache(vo.getAccessId(), redisUtil, true);
            BankCardModel bankCardOld = null;
            if (vo.getId() != null) {
                bankCardOld = bankCardModelMapper.selectByPrimaryKey(vo.getId());
                if (bankCardOld == null) {
                    throw new LaiKeAPIException(ErrorCode.BizErrorCode.OPERATION_FAILED, "银行卡不存在");
                }
            }
            //验证银行卡信息
            verificationBank(vo, vo.getBankName(), vo.getBankCardNumber());

            BankCardModel bankCardModel = new BankCardModel();
            bankCardModel.setStore_id(vo.getStoreId());
            bankCardModel.setUser_id(user.getUser_id());
            bankCardModel.setRecycle(DictionaryConst.ProductRecycle.NOT_STATUS);
            if (bankCardOld == null || !bankCardOld.getBank_card_number().equals(vo.getBankCardNumber())) {
                bankCardModel.setBank_card_number(vo.getBankCardNumber());
                if (bankCardModelMapper.selectCount(bankCardModel) > 0) {
                    throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_YXKYCZ, "银行卡已存在");
                }
            }
            //判断此银行卡是否为默认
            if (vo.getIsDefault() == 1) {
                int row = bankCardModelMapper.clearDefault(vo.getStoreId(), user.getUser_id());
                bankCardModel.setIs_default(DictionaryConst.WhetherMaven.WHETHER_OK);
            } else {
                //是否有默认,没有默认则设置默认
                BankCardModel bankCardModelTemp = bankCardModelMapper.getDefaultBankcardByUser(vo.getStoreId(), user.getUser_id());
                if (bankCardModelTemp == null) {
                    //没有默认必须要有一个默认
                    bankCardModel.setIs_default(DictionaryConst.WhetherMaven.WHETHER_OK);
                }
            }
            bankCardModel.setCardholder(vo.getCardholder());
            bankCardModel.setBank_name(vo.getBankName());
            bankCardModel.setBranch(vo.getBranchName());
            bankCardModel.setBank_card_number(vo.getBankCardNumber());
            bankCardModel.setAdd_date(new Date());
            //添加银行卡
            int count;
            if (bankCardOld == null) {
                count = bankCardModelMapper.insertSelective(bankCardModel);
            } else {
                bankCardModel.setId(bankCardOld.getId());
                count = bankCardModelMapper.updateByPrimaryKeySelective(bankCardModel);
            }
            if (count < 1) {
                throw new LaiKeAPIException(ErrorCode.BizErrorCode.OPERATION_FAILED, "操作失败");
            }
            return true;
        } catch (LaiKeAPIException l) {
            throw l;
        } catch (Exception e) {
            logger.error("添加银行卡 异常", e);
            throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_WLYC, "网络异常", "addBank");
        }
    }


    @Override
    @Transactional(rollbackFor = Exception.class)
    public void setDefaultBank(MainVo vo, int bankId) throws LaiKeAPIException {
        try {
            User user = RedisDataTool.getRedisUserCache(vo.getAccessId(), redisUtil, true);
            BankCardModel bankCardModel = new BankCardModel();
            bankCardModel.setUser_id(user.getUser_id());
            bankCardModel.setId(bankId);
            bankCardModel = bankCardModelMapper.selectOne(bankCardModel);
            if (bankCardModel == null) {
                throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_YXKBCZ, "银行卡不存在");
            }

            //清空之前默认
            int row = bankCardModelMapper.clearDefault(vo.getStoreId(), user.getUser_id());
            BankCardModel bankCardDefault = new BankCardModel();
            bankCardDefault.setId(bankId);
            bankCardDefault.setIs_default(DictionaryConst.WhetherMaven.WHETHER_OK);
            bankCardModelMapper.updateByPrimaryKeySelective(bankCardDefault);
        } catch (LaiKeAPIException l) {
            throw l;
        } catch (Exception e) {
            logger.error("设置默认银行卡 异常", e);
            throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_WLYC, "网络异常", "setDefaultBank");
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void delBank(MainVo vo, int bankId) throws LaiKeAPIException {
        try {
            User user = RedisDataTool.getRedisUserCache(vo.getAccessId(), redisUtil, true);
            BankCardModel bankCardModel = new BankCardModel();
            bankCardModel.setUser_id(user.getUser_id());
            bankCardModel.setId(bankId);
            bankCardModel = bankCardModelMapper.selectOne(bankCardModel);
            if (bankCardModel == null) {
                throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_YXKBCZ, "银行卡不存在");
            }
            BankCardModel bankCardUpdate = new BankCardModel();
            bankCardUpdate.setId(bankCardModel.getId());
            bankCardUpdate.setRecycle(DictionaryConst.ProductRecycle.RECOVERY);
            int row = bankCardModelMapper.updateByPrimaryKeySelective(bankCardUpdate);
            if (row < 1) {
                throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_CZSB, "操作失败");
            }
            //当前是否是默认银行卡,如果是则默认另外一张,否则不处理
            if (bankCardModel.getIs_default() == 1) {
                Integer id = bankCardModelMapper.getNewCardOneByUserId(user.getUser_id());
                if (id != null) {
                    BankCardModel bankCardDefault = new BankCardModel();
                    bankCardDefault.setId(id);
                    bankCardDefault.setIs_default(DictionaryConst.WhetherMaven.WHETHER_OK);
                    bankCardModelMapper.updateByPrimaryKeySelective(bankCardDefault);
                }
            }
        } catch (LaiKeAPIException l) {
            throw l;
        } catch (Exception e) {
            logger.error("解绑银行卡 异常", e);
            throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_WLYC, "网络异常", "delBank");
        }
    }

    @DubboApiMethod(apiKey = "com.laike.user.UserIndex",
            login = false, module = UserConst.MODULE_NAME, version = "1.0.0")
    @Override
    public Map<String, Object> index(MainVo vo, String mobile) throws LaiKeAPIException {
        Map<String, Object> resultMap = new HashMap<>(16);
        try {
            User user = null;
            Map<String, Object> dataMap = new HashMap<>(16);
            //插件状态
            Map<String, Integer> pluginMap = new HashMap<>(16);
            //用户信息
            Map<String, Object> userMap = new HashMap<>(16);
            //店铺商标
            String logoImg = "";
            //公司名称
            String company = "";
            //未读消息数量
            int notReadNum = 0;

            //是否同步
            int synchronizeFlag = 0;
            //是否为完善用户信息需要跳转
            boolean haveAllUserInfo = false;
            List<String> pluginCodeList = pluginsModelMapper.getPluginsCodeAll(vo.getStoreId());
            for (String pluginCode : pluginCodeList) {
                publiceService.frontPlugin(vo.getStoreId(), null, pluginCode, pluginMap);
            }
            //获取会员信息
            user = RedisDataTool.getRedisUserCache(vo.getAccessId(), redisUtil);
            if (user != null) {
                if (!StringUtils.isEmpty(mobile)) {
                    //查询手机号是否绑定其他账号（这个账户有可能就是新账户）
                    User userOld = userBaseMapper.getUserByMobile(vo.getStoreId(), vo.getAccessId(), mobile);
                    if (userOld != null) {
                        synchronizeFlag = 1;
                    } else {
                        //同步用户信息
                        userBaseMapper.syncUserInfo(vo.getAccessId(), mobile, vo.getStoreId());
                    }
                }
                //刷新缓存
                user = userBaseMapper.selectByPrimaryKey(user.getId());
                RedisDataTool.refreshRedisUserCache(user.getAccess_id(), user, redisUtil);
                if (user.getIs_default_value() != null && user.getIs_default_value() == 1){
                    haveAllUserInfo = true;
                }
                userMap.put("haveAllUserInfo", haveAllUserInfo);
                userMap.put("headimgurl", user.getHeadimgurl());
                String userName = user.getUser_name();
                userMap.put("user_name", userName);
                //保留两位小数
                userMap.put("money", user.getMoney().setScale(2,BigDecimal.ROUND_HALF_UP).toString());
                userMap.put("score", user.getScore());
                userMap.put("mobile", user.getMobile());
                userMap.put("zhanghao", user.getZhanghao());
                userMap.put("user_id", user.getUser_id());
                userMap.put("wx_name", user.getWx_name() == null ? "" : user.getWx_name());
                if (StringUtils.isEmpty(user.getWx_id())){
                    userMap.put("wx_withdraw", false);
                }else {
                    userMap.put("wx_withdraw", true);
                }
                //是否有登录密码
                userMap.put("isLoginPwd", StringUtils.isNotEmpty(user.getMima()));
                Date birthday = user.getBirthday();
                String birthdayFormat = "-0001-11-30";
                if (birthday != null) {
                    birthdayFormat = FastDateFormat.getInstance(GloabConst.TimePattern.YMD).format(birthday);
                }
                userMap.put("birthday", birthdayFormat);
                userMap.put("sex", user.getSex());

                //获取我的优惠卷数量
                Map<String, Object> couponMap = publicCouponService.mycoupon(vo.getStoreId(), user.getUser_id(), 0);
                List<Object> couponList = DataUtils.cast(couponMap.get("list"));
                int couponNum = 0;
                if (couponList != null) {
                    couponNum = couponList.size();
                }
                userMap.put("coupon_num", couponNum);
                //是否为分销商 1=true 0=false
                int isDistribution = 0;
                Integer mchIdMain = customerModelMapper.getStoreMchId(vo.getStoreId());
                //是否为总店
                boolean isMain = mchIdMain.equals(user.getMchId());
                //获取会员分销信息
                UserDistributionModel userDistributionModel = new UserDistributionModel();
                userDistributionModel.setStore_id(user.getStore_id());
                userDistributionModel.setUser_id(user.getUser_id());
                userDistributionModel = userDistributionModelMapper.selectOne1(userDistributionModel);
                if (userDistributionModel != null){
                    if (isMain || userDistributionModel.getLevel() > 0) {
                        isDistribution = 1;
                    }
                }
                userMap.put("isDistribution", isDistribution);
                userMap.put("is_default_birthday", user.getIs_default_birthday() == null ? 2 : user.getIs_default_birthday());
                //获取未读消息数量
                SystemMessageModel systemMessageModel = new SystemMessageModel();
                systemMessageModel.setStore_id(vo.getStoreId());
                systemMessageModel.setRecipientid(user.getUser_id());
                systemMessageModel.setType(1);
                notReadNum = systemMessageModelMapper.selectCount(systemMessageModel);

                String imgurlMy = "";
                BigDecimal rate = new BigDecimal("0");
                String imgurls = "";
                String fontColor = "";
                String dateColor = "";
                //会员过期处理
                if (user.getGrade_end() != null) {
                    if (DateUtil.dateCompare(new Date(), user.getGrade_end()) && String.valueOf(DictionaryConst.WhetherMaven.WHETHER_OK).equals(user.getIs_out())) {
                        User userUpdate = new User();
                        userUpdate.setId(user.getId());
                        userUpdate.setGrade(User.USER);
                        userUpdate.setIs_out(String.valueOf(DictionaryConst.WhetherMaven.WHETHER_OK));
                        userBaseMapper.updateByPrimaryKeySelective(userUpdate);
                    }
                }
                //获取会员等级信息
                Map<String, Object> memberInfo = new HashMap<>(16);
                memberInfo.put("grade", user.getGrade());
                memberInfo.put("tuiId", user.getTui_id());
                memberInfo.put("gradeAddTime", DateUtil.dateFormate(user.getGrade_add(), GloabConst.TimePattern.YMDHMS));
                memberInfo.put("gradeM", user.getGrade_m());
                memberInfo.put("gradeEndTime", DateUtil.dateFormate(user.getGrade_end(), GloabConst.TimePattern.YMDHMS));
                memberInfo.put("isOut", user.getIs_out());
                memberInfo.put("isBox", user.getIs_box());
                //会员提醒
                boolean remind = false;
                Map<String, Object> config = memberConfigMapper.getConfig(vo.getStoreId());
                if (MapUtils.getInteger(config, "id") != null && MapUtils.getInteger(config, "is_open") > 0) {
                    if (StringUtils.isNotEmpty(user.getUser_id())) {
                        if (Integer.parseInt(user.getIs_box()) == DictionaryConst.WhetherMaven.WHETHER_OK && user.getGrade().equals(User.MEMBER)) {
                            if (config != null && MapUtils.getInteger(config, "is_open") > 0) {
                                Integer renewOpen = MapUtils.getInteger(config, "renew_open");
                                if (renewOpen.equals(DictionaryConst.WhetherMaven.WHETHER_OK)) {
                                    if (user.getGrade_end() != null) {
                                        Integer renewDay = MapUtils.getInteger(config, "renew_day");
                                        long end = user.getGrade_end().getTime() / 1000;
                                        long now = new Date().getTime() / 1000;
                                        int betweenDate = DateUtil.getBetweenDate(now, end);
                                        if (betweenDate < renewDay) {
                                            remind = true;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                memberInfo.put("remind", remind);
                Map<String, Object> parmaMap = new HashMap<>(16);
                parmaMap.put("store_id", vo.getStoreId());
                //获取个人中心小红点
                int[] numArr = {DictionaryConst.OrdersStatus.ORDERS_R_STATUS_UNPAID, DictionaryConst.OrdersStatus.ORDERS_R_STATUS_CONSIGNMENT, DictionaryConst.OrdersStatus.ORDERS_R_STATUS_DISPATCHED, 3, 4};
                for (int num : numArr) {
                    List<String> orderTypeList = new ArrayList<>();
                    orderTypeList.add(DictionaryConst.OrdersType.ORDERS_HEADER_GM);

                    switch (num) {
                        case 3:
                            Map<String, Object> parmaMap1 = new HashMap<>(16);
                            parmaMap1.put("store_id", vo.getStoreId());
                            parmaMap1.put("user_id", user.getUser_id());
                            parmaMap1.put("typeList", orderTypeList);
                            parmaMap1.put("user_recycle", DictionaryConst.WhetherMaven.WHETHER_OK);
                            //待评价
                            int orderNum = orderModelMapper.countNotCommentNum(parmaMap1);
                            dataMap.put("dpj_num", orderNum);
                            break;
                        case 4:
                            //退款售后
                            List<Integer> typeList = new ArrayList<>();
                            typeList.add(0);
                            typeList.add(1);
                            typeList.add(3);
                            parmaMap.put("user_id", user.getUser_id());
                            parmaMap.put("rTypeList", typeList);
                            parmaMap.put("orderTypes", orderTypeList);
                            parmaMap.put("user_recycle", DictionaryConst.WhetherMaven.WHETHER_OK);
                            int number = returnOrderModelMapper.countRturnOrderNumDynamic(parmaMap);
                            dataMap.put("th", number);
                            break;
                        default:
                            //更具状态获取订单数量
                            Map<String, Object> parmaMap2 = new HashMap<>(16);
                            parmaMap2.put("status", num);
                            parmaMap2.put("store_id", vo.getStoreId());
                            parmaMap2.put("userId", user.getUser_id());
                            parmaMap2.put("orderTypeList", orderTypeList);
                            parmaMap2.put("user_recycle", DictionaryConst.WhetherMaven.WHETHER_OK);
                            orderNum = orderModelMapper.countDynamic(parmaMap2);
                            if (num == DictionaryConst.OrdersStatus.ORDERS_R_STATUS_UNPAID) {
                                dataMap.put("dfk_num", orderNum);
                            } else if (num == DictionaryConst.OrdersStatus.ORDERS_R_STATUS_CONSIGNMENT) {
                                dataMap.put("dfh_num", orderNum);
                            } else {
                                dataMap.put("dsh_num", orderNum);
                            }
                            break;
                    }
                }
                //获取微信小程序支付配置
                String paymentJson = paymentConfigModelMapper.getPaymentConfigInfo(vo.getStoreId(), DictionaryConst.OrderPayType.ORDERPAYTYPE_MINI_WECHAT);
                if (paymentJson != null){
                    paymentJson = URLDecoder.decode(paymentJson, GloabConst.Chartset.UTF_8);
                    JSONObject payJson = JSONObject.parseObject(paymentJson);
                    String mchID = payJson.getString("mch_id");
                    logger.info("获取微信小程序支付配置mch_id :" + mchID);
                    dataMap.put("merchant_id", mchID);
                }

                //获取收藏数量
                UserCollectionModel userCollectionModel = new UserCollectionModel();
                userCollectionModel.setStore_id(vo.getStoreId());
                userCollectionModel.setUser_id(user.getUser_id());
                userCollectionModel.setType(DictionaryConst.UserCollectionType.COLLECTIONTYPE1);
                int collectionNum = userCollectionModelMapper.selectCount(userCollectionModel);
                //默认获取自营店id
                Integer storeMchId = customerModelMapper.getStoreMchId(vo.getStoreId());
                dataMap.put("storeMchId", storeMchId);
                dataMap.put("user", userMap);
                dataMap.put("memberInfo", memberInfo);
                dataMap.put("logo", logoImg);
                dataMap.put("company", company);
                dataMap.put("collection_num", collectionNum);
                dataMap.put("footprint_num", collectionNum);
                dataMap.put("font_color", fontColor);
                dataMap.put("date_color", dateColor);
                dataMap.put("rate", rate);
                dataMap.put("imgurl_my", imgurlMy);
                dataMap.put("imgurl_s", imgurls);
                dataMap.put("xxnum", notReadNum);
                dataMap.put("synchronize_type", synchronizeFlag);
                resultMap.put("data", dataMap);
            } else {
                ConfigModel configOld = new ConfigModel();
                configOld.setStore_id(vo.getStoreId());
                configOld = configModelMapper.selectOne(configOld);
                String defaultHeaderImgUrl = "", defaultUserName = "";
                if (configOld != null) {
                    defaultHeaderImgUrl = publiceService.getImgPath(configOld.getWx_headimgurl(), vo.getStoreId());
                    defaultUserName = configOld.getWx_name();
                }
                resultMap.put("defaultHeaderImgUrl", defaultHeaderImgUrl);
                resultMap.put("defaultUserName", defaultUserName);
            }

            // TODO: 2024/4/17 【优化】  获取【我的-推荐】列表
            //获取【为您推荐】列表
            //商品状态 用于in查询
            List<Integer> goodsStatus = new ArrayList<>();

            //会员折扣率
            BigDecimal gradeRate = new BigDecimal("1");
            //商品信息
            List<Map<String, Object>> goodsList = new ArrayList<>();
            //获取商户产品配置
            ProductConfigModel productConfigModel = new ProductConfigModel();
            productConfigModel.setStore_id(vo.getStoreId());
            productConfigModel = productConfigModelMapper.selectOne(productConfigModel);
            //已上架
            goodsStatus.add(DictionaryConst.GoodsStatus.NEW_GROUNDING);
            if (productConfigModel != null && productConfigModel.getIs_open() != 0) {
                //已下架
                goodsStatus.add(DictionaryConst.GoodsStatus.OFFLINE_GROUNDING);
            }

            Map<String, Object> parmaMap1 = new HashMap<>(16);
            parmaMap1.put("store_id", vo.getStoreId());
            parmaMap1.put("GoodsStatus", goodsStatus);
            parmaMap1.put("is_open", MchModel.IS_OPEN_IN_BUSINESS);
            parmaMap1.put("show_adr", DictionaryConst.GoodsShowAdr.GOODSSHOWADR_MY);
            parmaMap1.put("sort_sort", DataUtils.Sort.DESC.toString());
            parmaMap1.put("pageNo", vo.getPageNo());
            parmaMap1.put("pageSize", vo.getPageSize());
            if (productConfigModel != null && productConfigModel.getIs_display_sell_put() == 0) {
                //不展示已售罄的商品
                parmaMap1.put("stockNum", "stockNum");
            }
            goodsList = productListModelMapper.getProductListDynamic(parmaMap1);
            for (Map<String, Object> map : goodsList) {
                String imgUrl = map.get("imgurl") + "";
                imgUrl = publicService.getImgPath(imgUrl, vo.getStoreId());
                int pid = Integer.parseInt(map.get("pid") + "");
                int stockNum = confiGureModelMapper.countConfigGureNum(pid);
                //店铺信息
                String logoUrl = publicService.getImgPath(MapUtils.getString(map, "logo"), vo.getStoreId());
                String mchName = map.get("mch_name").toString();
                //获取商品标签
                String sType = MapUtils.getString(map, "s_type");
                map.put("s_type_list", publicGoodsService.getGoodsLabelList(vo.getStoreId(), DataUtils.convertToList(com.laiketui.common.utils.tool.str.StringUtils.trim(sType, SplitUtils.DH).split(SplitUtils.DH))));

                //原来价格
                BigDecimal vipYprice = new BigDecimal(map.get("price") + "");
                //打折后的价格
                BigDecimal vipPrice = new BigDecimal(map.get("price") + "");
                if (gradeRate.floatValue() != 1) {
                    //折扣 原来价格 * 折扣  = 优惠价
                    vipPrice = vipYprice.multiply(gradeRate);
                }
                map.put("vip_yprice", vipYprice.toString());
                map.put("vip_price", vipPrice.toString());
                map.put("num", stockNum);
                map.put("imgurl", imgUrl);
                map.put("logo", logoUrl);
                map.put("mch_name", mchName);
            }
            resultMap.put("list",goodsList);
            resultMap.put("plugin", pluginMap);
        } catch (LaiKeAPIException l) {
            logger.error("获取我的数据异常 ", l);
            throw l;
        } catch (Exception e) {
            logger.error("获取我的数据异常 ", e);
            throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_WLYC, "网络异常", "index");
        }
        return resultMap;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    @DubboApiMethod(apiKey = "com.laike.user.bindPhone",
            login = true, module = UserConst.MODULE_NAME, version = "1.0.0")
    public void bindPhone(MainVo vo, String phone) throws LaiKeAPIException {
        try {
            //当前用户信息
            User userCache = RedisDataTool.getRedisUserCache(vo.getAccessId(), redisUtil);
            User user = new User();
            user.setStore_id(vo.getStoreId());
            user.setMobile(phone);
            User userDb = userBaseMapper.selectOne(user);
            if (Objects.isNull(userDb)) {
                userCache.setZhanghao(phone);
                userCache.setMobile(phone);
                userBaseMapper.updateUserInfoById(userCache);
                String token = vo.getAccessId();
                RedisDataTool.refreshRedisUserCache(token, userCache, redisUtil);
            }
        } catch (LaiKeAPIException e) {
            logger.error("绑定手机号码失败", e);
            throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_WLYC, "网络异常", "bindPhone");
        }


    }

    @Transactional(rollbackFor = Exception.class)
    @DubboApiMethod(apiKey = "com.laike.user.synchronizeAccount",
            login = true, module = UserConst.MODULE_NAME, version = "1.0.0")
    @Override
    public void synchronizeAccount(MainVo vo, String mobile, Integer source) throws LaiKeAPIException {
        try {
            //数据库老用户
            User userDb = userBaseMapper.getUserByMobile(vo.getStoreId(), vo.getAccessId(), mobile);
            //缓存新用户
            User userCache = RedisDataTool.getRedisUserCache(vo.getAccessId(), redisUtil);
            if (userDb != null) {
                int id = userCache.getId();
                int cacheId = userDb.getId();
                if (id != cacheId) {
                    if (DictionaryConst.StoreSource.LKT_LY_001.equals(source.toString())){
                        userDb.setWx_id(userCache.getWx_id());
                        //现在用户小程序登录没有获取到用户微信名称  合并不需要更新微信名称
//                        userDb.setWx_name(userCache.getWx_name());
                    }else {
                        userDb.setZfb_id(userCache.getZfb_id());
                    }
                    userDb.setAccess_id(userCache.getAccess_id());
                    userBaseMapper.delete(userCache);
                    userBaseMapper.updateByPrimaryKeySelective(userDb);
                    //更新用户数据
                    userDb = userBaseMapper.selectByPrimaryKey(userDb.getId());
                    RedisDataTool.refreshRedisUserCache(vo.getAccessId(), userDb, redisUtil);
                }
            } else {
                if (!Objects.isNull(userCache)) {
                    userCache.setMobile(mobile);
                    userCache.setZhanghao(mobile);
                    userBaseMapper.updateByPrimaryKeySelective(userCache);
                }
            }
        } catch (LaiKeAPIException e) {
            logger.error("同步微信小程序用户信息失败", e);
            throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_WLYC, "网络异常", "synchronizeAccount");
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Map<String, Object> synuser(SycnUserVo vo) throws LaiKeAPIException {
        Map<String, Object> resultMap = new HashMap<>(16);
        logger.info("同步用户信息：{}", JSON.toJSONString(vo));
        try {
            //数据库是否存在
            User userDb = userBaseMapper.getUserByUserFromID(vo.getStoreId(), vo.getUser_from_id());
            String token = null;
            if (userDb != null) {
                logger.info("用户已经存在：{}", JSON.toJSONString(userDb));
            } else {
                User user = new User();
                user.setUser_from_id(vo.getUser_from_id());
                user.setScore(vo.getSource());
                token = JwtUtils.getToken(publicUserService.getUserLoginLife(vo.getStoreId()));
                user.setAccess_id(token);
                if (StringUtils.isNotEmpty(vo.getUser_name())) {
                    user.setUser_name(vo.getUser_name());
                } else {
                    user.setUser_name("用户" + vo.getUser_from_id());
                }
                user.setStore_id(vo.getStoreId());
                user.setMobile(vo.getMobile());
                user.setZhanghao(vo.getMobile());
                publicUserService.register(vo, null, user);
                logger.info("用户不存在，保存信息：{}", JSON.toJSONString(user));
                userDb = user;
            }
            token = userDb.getAccess_id();
            //验证Token是否过期
            try {
                JwtUtils.verifyJwt(userDb.getAccess_id());
            } catch (LaiKeCommonException c) {
                logger.debug("token已过期!");
            }
            if (com.alibaba.druid.util.StringUtils.isEmpty(token)) {
                token = JwtUtils.getToken(publicUserService.getUserLoginLife(vo.getStoreId()));
            }
            publicUserService.loginSuccess(userDb, token, null);
            ConfigModel configModel = new ConfigModel();
            configModel.setStore_id(vo.getStoreId());
            configModel = configModelMapper.selectOne(configModel);
            String h5Url = "";
            if (configModel != null) {
                h5Url = configModel.getH5_domain();
            }

            resultMap.put("h5_url", h5Url + "pages/tabBar/Home?access_id=" + token + "&" + userDb.getUser_id() + "&" + userDb.getStore_id());
            resultMap.put("access_id", token);
            resultMap.put("store_id", vo.getStoreId());
        } catch (LaiKeAPIException e) {
            logger.error("同步微信小程序用户信息失败", e);
            throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_WLYC, "网络异常", "synchronizeAccount");
        }
        return resultMap;
    }

    @Override
    public Map<String, Object> getRecordDetails(MainVo vo, Integer id) throws LaiKeAPIException{
        Map<String, Object> resultMap = new HashMap<>(16);
        try {
            if (id == null){
                throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_CSCW, "参数错误", "getRecordDetails");
            }
            RecordDetailsModel recordDetailsModel = recordDetailsModelMapper.selectByPrimaryKey(id);
            if (recordDetailsModel == null){
                throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_JLBCZ, "记录不存在", "getRecordDetails");
            }

            resultMap.put("storeId", recordDetailsModel.getStore_id());
            resultMap.put("money", recordDetailsModel.getMoney());
            resultMap.put("userMoney", recordDetailsModel.getUserMoney());
            resultMap.put("type", recordDetailsModel.getType());
            resultMap.put("moneyType", recordDetailsModel.getMoneyType());
            resultMap.put("moneyTypeName", recordDetailsModel.getMoneyTypeName());
            resultMap.put("recordTime",DateUtil.dateFormate(recordDetailsModel.getRecordTime(), GloabConst.TimePattern.YMDHMS) );
            resultMap.put("recordNotes", recordDetailsModel.getRecordNotes());
            resultMap.put("typeName", recordDetailsModel.getTypeName());
            resultMap.put("sNo", recordDetailsModel.getsNo());
            resultMap.put("titleName", recordDetailsModel.getTitleName());
            resultMap.put("activityCode", recordDetailsModel.getActivityCode());
            resultMap.put("mchName", recordDetailsModel.getMchName());

            //余额提现特殊处理
            if (recordDetailsModel.getType().equals(RecordDetailsModel.type.WITHDRAWAL_OF_BALANCE)){
                String sNo = recordDetailsModel.getsNo();
                if (sNo == null){
                    throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_JLBCZ, "记录不存在", "getRecordDetails");
                }
                WithdrawModel withdrawModel = new WithdrawModel();
                withdrawModel.setTxsno(sNo);
                withdrawModel.setStore_id(vo.getStoreId());
                withdrawModel = withdrawModelMapper.selectOne(withdrawModel);
                if (withdrawModel == null){
                    throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_JLBCZ, "记录不存在", "getRecordDetails");
                }
                resultMap.put("withdrawalFees", recordDetailsModel.getWithdrawalFees());
                resultMap.put("withdrawalMethod", recordDetailsModel.getWithdrawalMethod());
                resultMap.put("status", withdrawModel.getStatus());
                resultMap.put("account", withdrawModel.getMoney().subtract(withdrawModel.getS_charge()).setScale(2, RoundingMode.HALF_DOWN).toString());
                resultMap.put("startTime", DateUtil.dateFormate(withdrawModel.getAdd_date(), GloabConst.TimePattern.YMDHMS));
                resultMap.put("withdrawStatus", withdrawModel.getWithdrawStatus());
                resultMap.put("wxStatus", withdrawModel.getWxStatus() == null ? "" : withdrawModel.getWxStatus());
                if (withdrawModel.getExamine_date() != null){
                    resultMap.put("examineTime", DateUtil.dateFormate(withdrawModel.getExamine_date(), GloabConst.TimePattern.YMDHMS));
                    resultMap.put("refuse", withdrawModel.getRefuse());
                }
            }
        }catch (LaiKeAPIException l) {
            logger.error("我的钱包记录详情 失败", l);
            throw l;
        }catch (Exception e){
            throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_WLYC, "网络异常", "getRecordDetails");
        }
        return resultMap;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void wxUnbind(MainVo vo) throws LaiKeAPIException {
        try {
            //获取会员信息
            User user = RedisDataTool.getRedisUserCache(vo.getAccessId(), redisUtil, true);
            //获取最新信息
            user = userBaseMapper.selectByUserId(vo.getStoreId(), user.getUser_id());
            //取消绑定
            user.setWx_name(null);
            user.setWx_id(null);
            if (userBaseMapper.updateByPrimaryKey(user) <= 0){
                throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_CZSB, "操作失败");
            }
        }catch (LaiKeAPIException l) {
            logger.error("用户解除与微信的绑定 失败", l);
            throw l;
        }catch (Exception e){
            throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_WLYC, "网络异常", "getRecordDetails");
        }
    }

    @Override
    public void  wxBind(MainVo vo, String openId, String wxName) throws LaiKeAPIException {
        try {
            if (StringUtils.isEmpty(openId)){
                throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_CSCW, "参数错误");
            }
            //获取会员信息
            User user = RedisDataTool.getRedisUserCache(vo.getAccessId(), redisUtil, true);
            //获取最新信息
            user = userBaseMapper.selectByUserId(vo.getStoreId(), user.getUser_id());
            //查询改openId是否已经绑定账户
            User odlUser = new User();
            odlUser.setStore_id(vo.getStoreId());
            odlUser.setWx_id(openId);
            if (userBaseMapper.selectCount(odlUser) > 0){
                throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_GWXYBDQTZH, "该微信已绑定其他账号");
            }

            //绑定
            if (StringUtils.isNotEmpty(wxName)){
                user.setWx_name(wxName);
            }
            user.setWx_id(openId);
            if (userBaseMapper.updateByPrimaryKeySelective(user) <= 0){
                throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_CZSB, "操作失败");
            }
        }catch (LaiKeAPIException l) {
            logger.error("用户解除与微信的绑定 失败", l);
            throw l;
        }catch (Exception e){
            throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_WLYC, "网络异常", "getRecordDetails");
        }
    }

    @Override
    public Map<String, Object> getMyRecommendation(MainVo vo) {
        Map<String, Object> resultMap = new HashMap<>(16);
        try{
            // TODO: 2024/4/17 【优化】  获取【我的-推荐】列表
            //获取【为您推荐】列表
            //商品状态 用于in查询
            List<Integer> goodsStatus = new ArrayList<>();

            //会员折扣率
            BigDecimal gradeRate = new BigDecimal("1");
            //商品信息
            List<Map<String, Object>> goodsList = new ArrayList<>();
            //获取商户产品配置
            ProductConfigModel productConfigModel = new ProductConfigModel();
            productConfigModel.setStore_id(vo.getStoreId());
            productConfigModel = productConfigModelMapper.selectOne(productConfigModel);
            //已上架
            goodsStatus.add(DictionaryConst.GoodsStatus.NEW_GROUNDING);
            if (productConfigModel != null && productConfigModel.getIs_open() != 0) {
                //已下架
                goodsStatus.add(DictionaryConst.GoodsStatus.OFFLINE_GROUNDING);
            }

            Map<String, Object> parmaMap1 = new HashMap<>(16);
            parmaMap1.put("store_id", vo.getStoreId());
            parmaMap1.put("GoodsStatus", goodsStatus);
//            parmaMap1.put("is_open", MchModel.IS_OPEN_IN_BUSINESS);
            parmaMap1.put("show_adr", DictionaryConst.GoodsShowAdr.GOODSSHOWADR_MY);
            parmaMap1.put("sort_sort", DataUtils.Sort.DESC.toString());
            parmaMap1.put("pageNo", vo.getPageNo());
            parmaMap1.put("pageSize", vo.getPageSize());
            if (productConfigModel != null && productConfigModel.getIs_display_sell_put() == 0) {
                //不展示已售罄的商品
                parmaMap1.put("stockNum", "stockNum");
            }
            goodsList = productListModelMapper.getProductListDynamic(parmaMap1);
            for (Map<String, Object> map : goodsList) {
                String imgUrl = map.get("imgurl") + "";
                imgUrl = publicService.getImgPath(imgUrl, vo.getStoreId());
                int pid = Integer.parseInt(map.get("pid") + "");
                int stockNum = confiGureModelMapper.countConfigGureNum(pid);
                //店铺信息
                String logoUrl = publicService.getImgPath(MapUtils.getString(map, "logo"), vo.getStoreId());
                String mchName = map.get("mch_name").toString();
                //获取商品标签
                String sType = MapUtils.getString(map, "s_type");
                map.put("s_type_list", publicGoodsService.getGoodsLabelList(vo.getStoreId(), DataUtils.convertToList(com.laiketui.common.utils.tool.str.StringUtils.trim(sType, SplitUtils.DH).split(SplitUtils.DH))));

                //原来价格
                BigDecimal vipYprice = new BigDecimal(map.get("price") + "");
                //打折后的价格
                BigDecimal vipPrice = new BigDecimal(map.get("price") + "");
                if (gradeRate.floatValue() != 1) {
                    //折扣 原来价格 * 折扣  = 优惠价
                    vipPrice = vipYprice.multiply(gradeRate);
                }
                map.put("vip_yprice", vipYprice.toString());
                map.put("vip_price", vipPrice.toString());
                map.put("num", stockNum);
                map.put("imgurl", imgUrl);
                map.put("logo", logoUrl);
                map.put("mch_name", mchName);

                int payPeople = orderDetailsModelMapper.payPeople(vo.getStoreId(), pid);
                map.put("payPeople", payPeople);
            }
            resultMap.put("list",goodsList);
        }catch (LaiKeAPIException l){
            logger.error("获取我的-推荐数据异常 ", l);
            throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_WLYC, "网络异常", "getMyRecommendation");
        }
        return resultMap;
    }
    @Override
    public void isDefaultValue(MainVo vo) throws LaiKeAPIException {
        try {
            User user = RedisDataTool.getRedisUserCache(vo.getAccessId(), redisUtil, true);
            User updateUser = new User();
            updateUser.setId(user.getId());
            updateUser.setIs_default_value(2);
            userBaseMapper.updateByPrimaryKeySelective(updateUser);
        } catch (LaiKeAPIException l) {
            throw l;
        } catch (Exception e) {
            logger.error("标记公告以读 异常", e);
            throw new LaiKeAPIException(ErrorCode.BizErrorCode.ERROR_CODE_WLYC, "网络异常", "markToRead");
        }
    }
    @Autowired
    private UserDistributionModelMapper userDistributionModelMapper;

    @Autowired
    private UserCollectionModelMapper userCollectionModelMapper;

    @Autowired
    private OrderModelMapper orderModelMapper;

    @Autowired
    private ReturnOrderModelMapper returnOrderModelMapper;

    @Autowired
    private UserRuleModelMapper userRuleModelMapper;

    @Autowired
    private UserGradeModelMapper userGradeModelMapper;

    @Autowired
    private SystemMessageModelMapper systemMessageModelMapper;

    @Autowired
    private PluginsModelMapper pluginsModelMapper;

    @Autowired
    private CouponConfigModelMapper couponConfigModelMapper;

    @Autowired
    private BankTool bankTool;

    @Autowired
    private MchModelMapper mchModelMapper;

    @Autowired
    private PubliceService publiceService;

    @Autowired
    private ConfigModelMapper configModelMapper;

    @Autowired
    private RecordModelMapper recordModelMapper;

    @Autowired
    private FinanceConfigModelMapper financeConfigModelMapper;

    @Autowired
    private WithdrawModelMapper withdrawModelMapper;

    @Autowired
    private UserBaseMapper userBaseMapper;

    @Autowired
    private BankCardModelMapper bankCardModelMapper;

    @Autowired
    private PublicCouponService publicCouponService;

    @Autowired
    private PaymentConfigModelMapper paymentConfigModelMapper;

    @Autowired
    RedisUtil redisUtil;

    @Autowired
    private PreSellRecordModelMapper preSellRecordModelMapper;

    @Autowired
    private PreSellGoodsMapper preSellGoodsMapper;

    @Autowired
    private MemberConfigMapper memberConfigMapper;

    @Autowired
    private CustomerModelMapper customerModelMapper;

    @Autowired
    private MessageLoggingModalMapper messageLoggingModalMapper;

    @Autowired
    private RecordDetailsModelMapper recordDetailsModelMapper;

    @Autowired
    private OrderDetailsModelMapper orderDetailsModelMapper;
}

